import React, { useEffect} from 'react';
import {
  Button,
  Form,
  Input,
  Switch,
} from 'antd';
import type { FormProps } from 'antd';
import { adddata, descdata } from '@/app/API/http';
interface Iprops{
    title:string,
    obj:any,
    get:()=>void,
    onCancel:()=>void
}
const AddEdit = (props:Iprops) => {
    const [form] = Form.useForm();
    useEffect(()=>{
        form.setFieldsValue(props.obj);
    }, [props.obj])
    const onFinish: FormProps<any>['onFinish'] = (values) => {
        let t=new Date().getTime();
        if(props.title=='添加'){
            let obj={
                ...values,
                id:t,
                time:t,
                send:t
            }
            adddata(obj).then((res)=>{
                props.get();
                props.onCancel();
            })
        }else{
            let obj={
                ...props.obj,
                ...values,  
            }
            descdata(obj).then((res)=>{
                props.get();
                props.onCancel();
            })
        }
      };

  return (
    <Form
    form={form}
    onFinish={onFinish}
      style={{ maxWidth: 600 }}
    >
    
      <Form.Item label="客户名称" name="name">
        <Input />
      </Form.Item>
      <Form.Item label="客户状态" name="Collect">
        <Switch />
      </Form.Item> 
      <Form.Item label="客户星级" name="value">
        <Input />
      </Form.Item>
      <Form.Item label="首联系人" name="sname">
        <Input />
      </Form.Item>
      <Form.Item label="未跟进天数" name="wgjts">
        <Input />
      </Form.Item>
      
      <Form.Item label="">
        <Button htmlType="submit">确认</Button>
      </Form.Item>
    </Form>
  );
};

export default AddEdit;
